package com.dpteam.dao.impl;

import com.dpteam.dao.RoleDao;
import com.dpteam.model.Permission;
import com.dpteam.model.Role;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xwh on 2016/1/7.
 */
@Repository
public class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDao {

    @Override
    public List<Role> findAllRole() {
        String hql = "from Role order by id ";
        return find(hql);
    }

    @Override
    public List<Permission> findAllPermissionByRoleType(String roleType) {
        String hql = "from Role where roleType = ?";
        return get(hql, roleType).getPermissionList();
    }

    @Override
    public void deleteById(int id) {
        Role role = get(Role.class, id);
        if (role != null) {
            delete(role);
        }
    }
}
